package com.hxc.shop.controller;

import com.hxc.shop.common.ResultVO;
import com.hxc.shop.service.GoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/category")
@CrossOrigin
@Api(tags = {"商品分类处理"})
public class GoodsCategoryController {
    @Resource
    private GoodsCategoryService goodsCategoryService;

    @ApiOperation("随机获取自定义个商品分类")
    @GetMapping("/getCategoryByCount")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "count",value = "随机获取的数量",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getCategoryByCount(@RequestParam("count")Integer count){
        return goodsCategoryService.getCategoryByCount(count);
    }

    @ApiOperation("获取所有商品分类")
    @GetMapping("/getAllCategory")
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getAllCategory(){
        return goodsCategoryService.getAllCategory();
    }

    @ApiOperation("根据商品分类名称获取商品分类")
    @GetMapping("/getCategoryByName")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryName",value = "商品分类名称",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getCategoryByName(@RequestParam("categoryName")String categoryName){
        return goodsCategoryService.getCategoryByName(categoryName);
    }

    @ApiOperation("更新商品分类")
    @GetMapping("/updateCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品分类编号",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "goodsCategory",value = "商品分类",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO updateCategory(@RequestParam("id")Integer id,@RequestParam("goodsCategory")String goodsCategory){
        return goodsCategoryService.updateCategory(id,goodsCategory);
    }

    @ApiOperation("插入商品分类")
    @GetMapping("/insertCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsCategory",value = "商品分类",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO insertCategory(@RequestParam("goodsCategory")String goodsCategory){
        return goodsCategoryService.insertCategory(goodsCategory);
    }

    @ApiOperation("删除商品分类")
    @GetMapping("/deleteCategory")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品分类编号",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO deleteCategory(@RequestParam("id")Integer id){
        return goodsCategoryService.deleteCategory(id);
    }

}
